all files / datePicker/ calendarMonth.vue

58.06% Statements 18/31
42.86% Branches 12/28
28.57% Functions 2/7
25% Lines 3/12
7 statements, 6 branches Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64                  1× 1×                                                                                                          
//
//
//
//
//
//
//
//
 
import dayButton from './dayButton'
import * as dateUtils from './dateUtils'
export default {
  props: {
    displayDate: {
      type: Date
    },
    firstDayOfWeek: {
      type: Number,
      default: 1
    },
    maxDate: {
      type: Date
    },
    minDate: {
      type: Date
    },
    selectedDate: {
      type: Date
    },
    shouldDisableDate: {
      type: Function
    }
  },
  data () {
    return {
      weeksArray: dateUtils.getWeekArray(this.displayDate || new Date(), this.firstDayOfWeek)
    }
  },
  methods: {
    equalsDate (date) {
      return dateUtils.isEqualDate(date, this.selectedDate)
    },
    isDisableDate (day) {
      if (day === null) return false
      let disabled = false
      if (this.maxDate && this.minDate) disabled = !dateUtils.isBetweenDates(day, this.minDate, this.maxDate)
      if (!disabled && this.shouldDisableDate) disabled = this.shouldDisableDate(day)
      return disabled
    },
    handleClick (date) {
      if (date) this.$emit('selected', date)
    }
  },
  watch: {
    displayDate (val) {
      return dateUtils.getWeekArray(val || new Date(), this.firstDayOfWeek)
    }
  },
  components: {
    'day-button': dayButton
  }
}